package com.lingxu.module.collection.controller;

import com.lingxu.base.common.api.vo.Result;
import com.lingxu.base.common.util.DateUtil;
import com.lingxu.base.system.manage.service.ISysDepartService;
import com.lingxu.module.collection.entity.ManageAnalysisSearchVo;
import com.lingxu.module.collection.entity.RedInfo;
import com.lingxu.module.collection.entity.UserCountInfo;
import com.lingxu.module.collection.service.IManageAnalysisService;
import com.lingxu.module.homeIndex.entity.ParamsDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@Slf4j
@Api(tags="统计分析-管理分析")
@RestController
@RequestMapping("/manageAnalysis")
public class ManageAnalysisController {

    @Autowired
    private IManageAnalysisService manageAnalysisService;
    @Autowired
    private ISysDepartService sysDepartService;

    @ApiOperation(value="管理分析-获取系统使用天数", notes="管理分析-获取系统使用天数")
    @PostMapping("/getSysUseDays")
    public Result<?> getSysUseDays() {
        String time = sysDepartService.getDictValueByDictNameAndDictCode("开始时间","sysStartTime");
        Date startdate = DateUtil.parseDate(time);
        Date enddate = new Date();
        Long starTime=startdate.getTime();
        Long endTime=enddate.getTime();
        Long num=endTime-starTime;//时间戳相差的毫秒数
        int days = (int) (num/24/60/60/1000);
              //  System.out.println("相差天数为："+num/24/60/60/1000);//除以一天的毫秒数
        return Result.ok(days);
    }

    @ApiOperation(value="管理分析-获取用户登录情况", notes="管理分析-获取用户登录情况")
    @PostMapping("/getUserLoginInfo")
    public Result<?> getUserLoginInfo(@RequestBody ManageAnalysisSearchVo vo) {
        List<UserCountInfo> list =manageAnalysisService.getUserLoginInfo(vo);
        return Result.ok(list);
    }

    @ApiOperation(value="管理分析-获取数据采集情况", notes="管理分析-获取数据采集情况")
    @PostMapping("/getDataCountInfo")
    public Result<?> getDataCountInfo(@RequestBody ManageAnalysisSearchVo vo) {
        List<UserCountInfo> list =manageAnalysisService.getDataCountInfo(vo);
        return Result.ok(list);
    }

    @ApiOperation(value="管理分析-获取模型创建情况", notes="管理分析-获取模型创建情况")
    @PostMapping("/getModelCountInfo")
    public Result<?> getModelCountInfo(@RequestBody ParamsDTO dto) {
        List<UserCountInfo> list =manageAnalysisService.getModelCountInfo(dto);
        return Result.ok(list);
    }
    @ApiOperation(value="管理分析-获取红名单维护和告警情况", notes="管理分析-获取红名单维护和告警情况")
    @PostMapping("/geRedListInfo")
    public Result<?> geRedListInfo(@RequestBody ManageAnalysisSearchVo vo) {
        RedInfo redInfo = new RedInfo();
        List<UserCountInfo> redMaintenanceList =manageAnalysisService.getRedMaintenanceList(vo);
        redInfo.setRedMaintenanceList(redMaintenanceList);
        List<UserCountInfo> redWarnList =manageAnalysisService.getRedWarnList(vo);
        redInfo.setRedWarnList(redWarnList);

        return Result.ok(redInfo);
    }


}
